import os

class filetype:
    def __init__(self, dir):
        self.files = []
        self.types = []
        self.dirs = []
        self.images = []
        self.audio = []
        self.ps = []
        self.snes = []
        self.n64 = []
        self.font = []
        self.movie = []
        self.files = os.listdir(dir)
        self.files.sort()

        # DONE
        for i in range (0, len(self.files)):
            path = os.path.join(dir, self.files[i])
            self.types.append("unknown")

            # CHECK IF PATH EXISTS
            if os.path.exists(path) == True:

                # Directory
                if os.path.isdir(path) == True:
                    self.types[i] = "directory"
                    self.dirs.append(self.files[i])

                # FILES
                if os.path.isfile(path) == True:
                    self.types[i] = "file"
                    # IMAGES
                    if self.files[i][-3:] == "png" or self.files[i][-3:] == "jpg" or self.files[i][-3:] == "gif":
                        self.types[i] = "image"
                        self.images.append(self.files[i])
                    # AUDIOFILES
                    if self.files[i][-3:] == "ogg" or self.files[i][-3:] == "mp3": #or self.files[i][-3:] == "wma":
                        self.types[i] = "audio"
                        self.audio.append(self.files[i])
                    # PlayStation "ROMS"
                    if self.files[i][-3:] == "bin" or self.files[i][-3:] == "iso":
                        self.types[i] = "ps"
                        self.ps.append(self.files[i])
                    # SNES ROMS
                    if self.files[i][-3:] == "smc":
                        self.types[i] = "snes"
                        self.snes.append(self.files[i])
                    # N64 ROMS
                    if self.files[i][-3:] == "z64" or self.files[i][-3:] == "v64":
                        self.n64.append(self.files[i])
                    # FONTS
                    if self.files[i][-3:] == "ttf":
                        self.types[i] = "font"
                        self.font.append(self.files[i])
                    # MOVIES ;)
                    #if self.files[i][-3:] == "mpg" or self.files[i][-3:] == "avi" or self.files[i][-3:] == "wmv" or self.files[i][-3:] == "mov":
                    #    self.types[i] = "movie"
                    #    self.movie.append(self.files[i])
